package com.ruoyi.web.controller.video;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.VsUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.video.VsDramasVideoLog;
import com.ruoyi.system.service.video.IVsDramasVideoLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * This file is part of 南阳迈特网络科技有限公司.
 * @company  南阳迈特网络科技有限公司
 * @link     https://www.nymaite.com
 * @document https://product.nymaite.cn
 * @contact  service@nymaite.com
 * @author nymaite
 */
/**
 * 追剧记录Controller
 * 
 * @author zzx
 * @date 2024-04-30
 */
@Api(tags = "追剧记录")
@RestController
@RequestMapping("/video/log")
public class VsDramasVideoLogController extends BaseController
{
    @Autowired
    private IVsDramasVideoLogService vsDramasVideoLogService;

    /**
     * 查询追剧记录列表
     */
    @ApiOperation("查询追剧记录列表")
    @GetMapping("/list")
    public TableDataInfo list(VsDramasVideoLog vsDramasVideoLog)
    {
        startPage();
        List<VsDramasVideoLog> list = vsDramasVideoLogService.selectVsDramasVideoLogList(vsDramasVideoLog);
        return getDataTable(list);
    }

    /**
     * 导出追剧记录列表
     */
//    @ApiOperation("导出追剧记录列表")
    @Log(title = "追剧记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VsDramasVideoLog vsDramasVideoLog)
    {
        List<VsDramasVideoLog> list = vsDramasVideoLogService.selectVsDramasVideoLogList(vsDramasVideoLog);
        ExcelUtil<VsDramasVideoLog> util = new ExcelUtil<VsDramasVideoLog>(VsDramasVideoLog.class);
        util.exportExcel(response, list, "追剧记录数据");
    }

    /**
     * 获取追剧记录详细信息
     */
//    @ApiOperation("获取追剧记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(vsDramasVideoLogService.selectVsDramasVideoLogById(id));
    }

    /**
     * 新增追剧记录
     */
    @ApiOperation("新增追剧记录")
    @Log(title = "追剧记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VsDramasVideoLog vsDramasVideoLog)
    {
        return toAjax(vsDramasVideoLogService.insertVsDramasVideoLog(vsDramasVideoLog));
    }

    /**
     * 修改追剧记录
     */
//    @ApiOperation("修改追剧记录")
    @Log(title = "追剧记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VsDramasVideoLog vsDramasVideoLog)
    {
        return toAjax(vsDramasVideoLogService.updateVsDramasVideoLog(vsDramasVideoLog));
    }

    /**
     * 删除追剧记录
     */
//    @ApiOperation("删除追剧记录")
    @Log(title = "追剧记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(vsDramasVideoLogService.deleteVsDramasVideoLogByIds(ids));
    }

    @ApiOperation("删除追剧记录")
    @PostMapping("/removeLog")
    public AjaxResult removeLog(@RequestBody VsDramasVideoLog vsDramasVideoLog) {
        if (StringUtils.isEmpty(vsDramasVideoLog.getType())) {
            return error("类型为空！");
        }
        if (vsDramasVideoLog.getVid() == null && vsDramasVideoLog.getEpisodeId() == null) {
            return error("剧集信息为空！");
        }
        try {
            VsUser user = SecurityUtils.getLoginUser().getVsUser();
            vsDramasVideoLog.setUserId(user.getId());
        } catch (Exception e) {
            return error(e.getMessage());
        }
        int i = vsDramasVideoLogService.removeLog(vsDramasVideoLog);
        if (i > 0) {
            return success();
        }
        return error();
    }

}
